from OpenGL.arrays import vbo
from OpenGL.GLUT import *
from OpenGL.GLU import *
from OpenGL.GL import *
from numpy import array
import sys, math, os
from collections import namedtuple

def init(width, height):
   """ Initialize an OpenGL windown and rendering context"""
   glClearColor(0.0, 0.0, 0.0, 0.0)         #background color
   glMatrixMode(GL_PROJECTION)              #switch to projection matrix
   glLoadIdentity()                         #set to 1
   gluPerspective(45., float(width)/height, 0.1, 100.0)
   glMatrixMode(GL_MODELVIEW)               #switch to modelview matrix
   
def display():
   """Rendering einstellungen"""
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT) # resettet angegebenen Buffer
   glLoadIdentity() # Modelview Matrix resetten
   gluLookAt(0.0, 0.0, 0.0, 4.0, -2.0, 0, 0, 1, 0.0) # (eye, center, 
   glTranslate(4.0, 0.0, 0.0) # nach vorne verschieben sonst sehen wir das innere des teapot
   glRotate(90.0, 0.0, 1.0, 0.0) # drehe auf x-achse (winkel, xyz fuer achse)
   glTranslate(0, -2, 0)
   glutWireTeapot(1.) # Draht-Teapot erzeugen
   glutSwapBuffers() # neugezeichneten Backbuffer nach vorne/anzeigen
   
 
def reshape():
   pass
   
def main():
   width, height = 500, 500
   glutInit(sys.argv)
   glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL)   
   glutInitWindowSize(width, height)
   glutCreateWindow("Test OPENGL Fensterchen")
   glutDisplayFunc(display)     #register display function

   
   # Hack for Mac OS X
#   cwd = os.getcwd()
#   glutInit(sys.argv)
#   os.chdir(cwd)

   init(width, height)#initialize OpenGL state and opengl context
   glutMainLoop()   #start even processing

if __name__ == "__main__":
   main()
